function url(p) {
  return `${window.RPConfig.mgt}/tree/${p}`;
  // return `/tree/${p}`
}
function url2(p) {
  return `${window.RPConfig.mgt}/employee/${p}`;
  // return `/employee/${p}`
}

function organizationApi(p) {
  return `${window.RPConfig.mgt}/organization/${p}`;
  // return `/employee/${p}`
}

// 查询树列表 CR_PHARM_HR
export const findTreeList = params => $http.get(organizationApi(`getOrgAndDeptTreeByUserId`), params);

export const getTreeList = params => $http.post(organizationApi(`getOrgTreeByUser?orgType=${2}&enabled=${1}&nameOrCode=${params.nameOrCode}`), params);

// 查询职位树列表
export const findPositionTreeList = params => $http.post(`${window.RPConfig.mgt}/position/getPositionTree`, params);

// 节点筛选
export const filterTree = param => $http.post(url("node/select"), param);

// 查询树下的员工信息
// http://yapi.dev.crc.com.cn/mock/23
export const findEmployeeList = param => $http.post(url2("list/page"), param);

// 查询树节点
export const findTreeNode = id => $http.post(url(`node/list?nodeId=${id}`));

// getOrgsByPostId
export const getOrgsByPostId = postId => $http.post(url(`node/getOrgsByPostId?postId=${postId}`));

const treeAPI = {
  // 查询树节点
  selectTreeNode: param => {
    return $http.post(`${window.RPConfig.mgt}/tree/node/select`, param).then(response => response.data);
  },
  // 查询树节点
  getTreeNodedetail: param => {
    return $http.post(`${window.RPConfig.mgt}/tree/node/detail`, param).then(response => response.data);
  },
  // 根据nodePath 查询树
  getParentTreeByTreeNodePath: param => {
    return $http.get(`${window.RPConfig.mgt}/tree/getParentTreeByTreeNodePath`, param).then(response => response.data);
  },
  // 根据父节点查询树节点
  queryTreeNode: nodeId => {
    return $http.post(`${window.RPConfig.mgt}/tree/node/list?nodeId=${nodeId}`).then(response => response.data);
  },
  // 新增树节点
  addTreeNode: param => {
    return $http.post(`${window.RPConfig.mgt}/tree/node/add`, param).then(response => response.data);
  },
  // 更新树节点
  updateTreeNode: param => {
    return $http.post(`${window.RPConfig.mgt}/tree/node/update`, param).then(response => response.data);
  },
  // 删除树节点
  deleteTreeNode: param => {
    return $http.post(`${window.RPConfig.mgt}/tree/node/delete`, param).then(response => response.data);
  }
};
export default treeAPI;
